package edu.hawaii.senin.iclouds.util;

import java.io.File;

import javax.swing.filechooser.FileFilter;

/**
 * Provides file filter class to filter out only XML stuff.
 * 
 * @author Pavel Senin
 * 
 */
public class TraffoFilter
    extends FileFilter {

  /**
   * Accept all directories and all xml files.
   * 
   * @param file file/folder name to filter.
   * @return true if this is XML file or directory, false elsewhere.
   */
  @Override
  public boolean accept(File file) {
    if (file.isDirectory()) {
      return true;
    }
    String extension = Utils.getExtension(file);
    if ((extension != null) && (extension.equals(Utils.xml))) {
      return true;
    }
    return false;
  }

  /**
   * Returns filter description.
   * 
   * @return string containing filter description.
   */
  @Override
  public String getDescription() {
    return "Just xml files";
  }
}